#ifndef __PCIKBOT_LOADER_LOADER_H__
#define __PCIKBOT_LOADER_LOADER_H__
#include <windows.h>

#include "singleton.hpp"

typedef HWND (WINAPI* API_SetFocus)(HWND hWnd);
typedef bool (__stdcall* DllInitialize)(HINSTANCE dll_hanlde);
typedef void (__stdcall* DllFinalize)();

typedef HWND (WINAPI* DllSetFocusHandler)(API_SetFocus handler, HWND hWnd);
typedef LRESULT	(CALLBACK* DllKeyBoardProcHandler)(HHOOK hook_handle, int nCode, WPARAM wParam, LPARAM lParam);
typedef LRESULT (CALLBACK* DllWndProcHandler)(WNDPROC game_wnd_proc, HWND hWnd, UINT wMsg, WPARAM wParam,LPARAM lParam);


class Loader : public core::singleton<Loader>
{
	friend core::singleton<Loader>;

private:
	Loader()
		: hook_handle_(NULL), self_handle_(NULL), dll_handle_(NULL), is_initialized_(false), game_wnd_proc_(NULL), dll_wnd_proc_handler_(NULL)
	{}

public:
	~Loader()
	{}

public:
	bool Initialize(HINSTANCE dll_hanlde);
	void Finalize();

public:
	LRESULT KeyBoardProc(int nCode,WPARAM wParam,LPARAM lParam);
	LRESULT GameWndProcHandler(HWND hWnd, UINT wMsg, WPARAM wParam,LPARAM lParam);
	HWND SetFocusHandler(HWND hWnd);

private:
	void InstallInlineHook();
	void UninstallInlineHook();
	void InstallHook();
	BOOL UninstallHook();

private:
	HHOOK hook_handle_;
	HINSTANCE self_handle_;
	std::string dll_path_;
	HINSTANCE dll_handle_;
	bool is_initialized_;
	HWND game_wnd_handle_;
	WNDPROC game_wnd_proc_;
	API_SetFocus set_focus_;

	DllKeyBoardProcHandler dll_key_board_handler_;
	DllWndProcHandler dll_wnd_proc_handler_;
	DllSetFocusHandler dll_set_focus_handler_;
};
#define sLoader Loader::get_instance()
#endif//__PCIKBOT_LOADER_LOADER_H__